class AdminController < ApplicationController
  before_filter :authenticate
=begin
    *Submission control structure
=end
  def submissions
    @title = "Listing all submissions"
    @teams = Team.find(:all)
  end

  def edit_submission
    @submission = Submission.find(params[:submission])
    @title = "Editing " + @submission.name
  end

  def destroy_submission
    submission = Submission.find(params[:submission])
    flash[:notice] = "Submission was successfully deleted: #{submission.name}"
    submission.destroy
    redirect_to :action => 'submissions'
  end

  def save_submission
    submission = Submission.find(params[:edit][:id].to_i)
    submission.status = params[:edit][:submission_status]

    submission.save

    redirect_to :action => 'submissions'
  end

=begin
    *Submission control structure end
=end                   

=begin
    *Problem control structure
=end
def problems
  @problems = Problem.find(:all)
  @title = "Problems"
end

def edit_problem
  @problem = Problem.find(params[:problem])
end 

def destroy_problem
  problem = Problem.find(params[:problem])
  flash[:notice] = "Problem was successfully deleted: #{problem.name}"
  problem.destroy
  redirect_to :action => 'problems'
end

def save_problem
  problem = Problem.find(params[:edit][:id].to_i)   

  problem.input  = params[:edit][:input].read
  problem.output = params[:edit][:output].read

  problem.save

  redirect_to :action => 'problems'
end

#TODO
#Create functionality to create new problems
def new_problem
end
=begin
    *Problem control structure end
=end

=begin
    *Team control structure
=end
def teams
  @title = "Teams"
  @teams = Team.find(:all)
end

def edit_team
  @team = Team.find(params[:team])
end 

def destroy_team
  team = Team.find(params[:team])
  flash[:notice] = "Team was successfully deleted: #{team.name}"
  team.destroy
  redirect_to :action => 'teams'
end

def save_team
  team = Team.find(params[:id])   

  team.name  = params[:edit][:name]
  team.password = params[:edit][:password]

  team.save

  redirect_to :action => 'teams'
end

def new_team
end

def create_team
  team = Team.new

  team.name  = params[:edit][:name]
  team.password = params[:edit][:password]

  team.save

  redirect_to :action => 'teams'
end

=begin 
    *Team control structure end
=end

end
